SHED.Window = Ext.extend(Ext.Window, {
    buttonAlign: 'center',
    layout: 'fit',
    minWidth: 370,
    width: 370,
    height: 300,
    closeAction: 'hide',
    plain: true,
    modal: true,
    getForm: function(){
        return this.form;
    },
    getBasicForm: function(){
        return this.basicForm;
    },
    onRender: function(ct, position){
        SHED.Window.superclass.onRender.call(this, ct, position);
        
        if (this.items.get(0) && this.items.get(0) instanceof SHED.form.DWRForm) {
            this.form = this.items.get(0);
            this.basicForm = this.form.form;
        }
    },
    show: function(animateTarget, cb, scope){
        SHED.Window.superclass.show.call(this, animateTarget, cb, scope);
        
        if (this.basicForm) {
            this.basicForm.reset();
            this.basicForm.isValid();
            this.action = 'save';
        }
    },
    load: function(params, animateTarget, cb, scope){
        SHED.Window.superclass.show.call(this, animateTarget, cb, scope);
        
        if (this.form) {
            this.form.load(params);
            this.action = 'update';
        }
    },
    buttons: [{
        text: '确定',
        handler: function(o){
            var form = o.ownerCt.getBasicForm();
            if (form) {
                if (form.isValid()) {
                    Ext.Msg.confirm('提交', '确认要提交表单里的内容吗？', function(para){
                        if (para == 'yes') {
                            o.ownerCt.form[o.ownerCt.action]();
                        }
                    });
                } else {
                    SHED.msg('表单中的字段未通过效验，请检查后再提交！');
                }
            }
        }
    }, {
        text: '取消',
        handler: function(o){
            o.ownerCt.hide();
        }
    }]
});
